<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: ActiveSupport::Duration</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">ActiveSupport::Duration</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/activesupport/lib/active_support/duration_rb.html">
                vendor/rails/activesupport/lib/active_support/duration.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                BasicObject
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Provides accurate date and time measurements using Date#advance and
Time#advance, respectively. It mainly supports the methods on Numeric, such
as in this example:
</p>
<pre>
  1.month.ago       # equivalent to Time.now.advance(:months =&gt; -1)
</pre>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000771">+</a>&nbsp;&nbsp;
      <a href="#M000772">-</a>&nbsp;&nbsp;
      <a href="#M000773">==</a>&nbsp;&nbsp;
      <a href="#M000776">ago</a>&nbsp;&nbsp;
      <a href="#M000775">from_now</a>&nbsp;&nbsp;
      <a href="#M000774">since</a>&nbsp;&nbsp;
      <a href="#M000777">until</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">parts</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">value</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000771" class="method-detail">
        <a name="M000771"></a>

        <div class="method-heading">
          <a href="#M000771" class="method-signature">
          <span class="method-name">+</span><span class="method-args">(other)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Adds another <a href="Duration.html">Duration</a> or a Numeric to this <a
href="Duration.html">Duration</a>. Numeric values are treated as seconds.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000771-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000771-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/duration.rb, line 16</span>
16:     <span class="ruby-keyword kw">def</span> <span class="ruby-operator">+</span>(<span class="ruby-identifier">other</span>)
17:       <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Duration</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">other</span>
18:         <span class="ruby-constant">Duration</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">value</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">value</span>, <span class="ruby-ivar">@parts</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">parts</span>)
19:       <span class="ruby-keyword kw">else</span>
20:         <span class="ruby-constant">Duration</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">value</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">other</span>, <span class="ruby-ivar">@parts</span> <span class="ruby-operator">+</span> [[<span class="ruby-identifier">:seconds</span>, <span class="ruby-identifier">other</span>]])
21:       <span class="ruby-keyword kw">end</span>
22:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000772" class="method-detail">
        <a name="M000772"></a>

        <div class="method-heading">
          <a href="#M000772" class="method-signature">
          <span class="method-name">-</span><span class="method-args">(other)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Subtracts another <a href="Duration.html">Duration</a> or a Numeric from
this <a href="Duration.html">Duration</a>. Numeric values are treated as
seconds.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000772-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000772-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/duration.rb, line 26</span>
26:     <span class="ruby-keyword kw">def</span> <span class="ruby-operator">-</span>(<span class="ruby-identifier">other</span>)
27:       <span class="ruby-keyword kw">self</span> <span class="ruby-operator">+</span> (<span class="ruby-operator">-</span><span class="ruby-identifier">other</span>)
28:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000773" class="method-detail">
        <a name="M000773"></a>

        <div class="method-heading">
          <a href="#M000773" class="method-signature">
          <span class="method-name">==</span><span class="method-args">(other)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if <tt>other</tt> is also a <a
href="Duration.html">Duration</a> instance with the same <tt>value</tt>, or
if <tt>other == value</tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000773-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000773-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/duration.rb, line 40</span>
40:     <span class="ruby-keyword kw">def</span> <span class="ruby-operator">==</span>(<span class="ruby-identifier">other</span>)
41:       <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Duration</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">other</span>
42:         <span class="ruby-identifier">other</span>.<span class="ruby-identifier">value</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">value</span>
43:       <span class="ruby-keyword kw">else</span>
44:         <span class="ruby-identifier">other</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">value</span>
45:       <span class="ruby-keyword kw">end</span>
46:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000776" class="method-detail">
        <a name="M000776"></a>

        <div class="method-heading">
          <a href="#M000776" class="method-signature">
          <span class="method-name">ago</span><span class="method-args">(time = ::Time.now)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Calculates a new Time or Date that is as far in the past as this <a
href="Duration.html">Duration</a> represents.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000776-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000776-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/duration.rb, line 61</span>
61:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ago</span>(<span class="ruby-identifier">time</span> = <span class="ruby-operator">::</span><span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>)
62:       <span class="ruby-identifier">sum</span>(<span class="ruby-value">-1</span>, <span class="ruby-identifier">time</span>)
63:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000775" class="method-detail">
        <a name="M000775"></a>

        <div class="method-heading">
          <span class="method-name">from_now</span><span class="method-args">(time = ::Time.now)</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="Duration.html#M000774">since</a>
</p>
        </div>
      </div>

      <div id="method-M000774" class="method-detail">
        <a name="M000774"></a>

        <div class="method-heading">
          <a href="#M000774" class="method-signature">
          <span class="method-name">since</span><span class="method-args">(time = ::Time.now)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Calculates a new Time or Date that is as far in the future as this <a
href="Duration.html">Duration</a> represents.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000774-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000774-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/duration.rb, line 54</span>
54:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">since</span>(<span class="ruby-identifier">time</span> = <span class="ruby-operator">::</span><span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>)
55:       <span class="ruby-identifier">sum</span>(<span class="ruby-value">1</span>, <span class="ruby-identifier">time</span>)
56:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000777" class="method-detail">
        <a name="M000777"></a>

        <div class="method-heading">
          <span class="method-name">until</span><span class="method-args">(time = ::Time.now)</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="Duration.html#M000776">ago</a>
</p>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>